/* 
 * File:   wiwannSound.h
 * Author: manu
 *
 * Created on 14 novembre 2010, 15:55
 */

#ifndef _WIWANNSOUND_H
#define	_WIWANNSOUND_H

//package build-essential
#include <stdlib.h>
#include <vector>
#include <string.h>
#include <string>

//from package libopenal-dev
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alext.h>
//from package libalut-dev
#include <AL/alut.h>

//wiwann
#include "wiwannTypes.h"



std::string wiwannSoundGetALErrorString(ALenum err)
{
    switch(err)
    {
        case AL_NO_ERROR:
            return std::string("AL_NO_ERROR");
        break;

        case AL_INVALID_NAME:
            return std::string("AL_INVALID_NAME_OR_DEVICE");
        break;

        case AL_INVALID_ENUM:
            return std::string("AL_INVALID_ENUM_OR_CONTEXT");
        break;

        case AL_INVALID_VALUE:
            return std::string("AL_INVALID_VALUE");
        break;

        case AL_INVALID_OPERATION:
            return std::string("AL_INVALID_OPERATION");
        break;

        case AL_OUT_OF_MEMORY:
            return std::string("AL_OUT_OF_MEMORY");
        break;

        default:
            return std::string("indeterminee");
    };
}

void wiwannSoundCheckErrors()
{
    ALenum result;
    if ((result = alGetError()) != AL_NO_ERROR)
    {
        std::cout << "erreur openAL détectée " <<  wiwannSoundGetALErrorString(result) ;
        throw wiwannSoundGetALErrorString(result) ;
    }
}

bool wiwannSoundInit()
{
    alutInit(NULL, NULL);
    /*
    std::cout << "\n entree init\n" ;
    alGetError();
    // Ouverture du device
    ALCdevice* Device = alcOpenDevice(NULL);
    //wiwannSoundCheckErrors();
    if (!Device)
        return false;
std::cout << "\ncreation contexte\n" ;
    // Création du contexte
    ALCcontext* Context = alcCreateContext(Device,NULL);
    //wiwannSoundCheckErrors();
    if (!Context)
        return false;

    std::cout << "\nactivation contexte\n" ;
    // Activation du contexte
if (!alcMakeContextCurrent(Context))
{
// wiwannSoundCheckErrors();
return false;
}
     * */
        
std::cout << "\nplacement listener\n" ;
    // Position of the listener.
    ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };

    // Velocity of the listener.
    ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };

    // Orientation of the listener. (first 3 elements are "at", second 3 are "up")
    ALfloat ListenerOri[] = { 0.0, 0.0, -1.0,  0.0, 1.0, 0.0 };


    alListenerfv(AL_POSITION,    ListenerPos);
    alListenerfv(AL_VELOCITY,    ListenerVel);
    alListenerfv(AL_ORIENTATION, ListenerOri);

    std::cout << "\nok sortie init\n" ;
    return true;
}







WIWANNuint wiwannConvertTypes(WIWANNuint context,WIWANNuint value)
{
    switch (context)
    {
        case WIWANN_SOUND_DRIVER_OPENAL :
            switch(value)
            {
                case WIWANN_SOUND_FORMAT_MONO16:
                    return AL_FORMAT_MONO16 ;
            }
    }
}









#endif	/* _WIWANNSOUND_H */

